<?php

namespace app\admin\controller;
use app\common\controller\Base;
class User extends Base
{
    /**
     * 显示资源列表
     */
    public function index()
    {
        $page = input('get.page',1);
        $numPage = 2;
        $startPage = ($page-1) * $numPage;
        $count = db('user')->count();
        $data = db('user')->limit($startPage,$numPage)->select();
        $pages = ceil(($count/$numPage));
        $this->assign('page',$page);
        $this->assign('pages',$pages);
        $this->assign('data', $data);
        $this->assign('count', $count);
        return view();
    }

    /**
     * 删除指定资源
     */
    public function delete()
    {
        $ids = input('post.id','');
        if(!$ids) return json(['status'=>0,'msg'=>'请选择要删除的会员!']);
        return db('user')->delete($ids) ? json(['status'=>1,'msg'=>'已删除!']) : json(['status'=>0,'msg'=>'删除失败!']);
    }

    /**
     * 状态操作
     */
    public function status()
    {
        $id = input('post.id', '');
        $status = input('post.status', '');
        return ($status ? db('user')->where('id', $id)->update(['status' => '0']) : db('user')->where('id', $id)->update(['status' => '1'])) ? json(['status'=>1]) : json(['status'=>0,'msg'=>'更新状态失败!']);
    }

}
